package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessPayPassword;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.widget.EditTextWithClear;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/9/30 11:12
 * 修改备注：
 * ================================================
 */
public class AmendPayPasswordActivity extends BaseActivity {
    @Bind(R.id.et_old_password)
    EditTextWithClear etOldPassword;
    @Bind(R.id.et_new_password)
    EditTextWithClear etNewPassword;
    @Bind(R.id.et_confirm_password)
    EditTextWithClear etConfirmPassword;
    @Bind(R.id.bt_save)
    Button btSave;
    @Bind(R.id.tv_forgot)
    TextView tvForgot;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_amend_pay_password);
        setTitle("修改支付密码");
    }

    @Override
    public void initMember() {

    }

    @Override
    public void addListener() {
        btSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String strOldPwd = StringUtil.getEditText(etOldPassword);
                String strNewPwd = StringUtil.getEditText(etNewPassword);
                String strConfirmPwd = StringUtil.getEditText(etConfirmPassword);

                if (StringUtil.isStrEmpty(strOldPwd)) {
                    showToast("原密码不能为空");
                    return;
                }
                if (StringUtil.isStrEmpty(strNewPwd)) {
                    showToast("新密码不能为空");
                    return;
                }
                if (StringUtil.isStrEmpty(strConfirmPwd)) {
                    showToast("确认密码不能为空");
                    return;
                }
                if (!StringUtil.isStrEqual(strNewPwd, strConfirmPwd)) {
                    showToast("新密码与确认密码不一致");
                    return;
                }

                BusinessPayPassword.updatePayPassword(AmendPayPasswordActivity.this, strOldPwd, strNewPwd, strConfirmPwd, mHandler);
            }
        });

        tvForgot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GotoUtil.gotoActivity(AmendPayPasswordActivity.this, SetPayPasswordOneActivity.class, true,"type",1);
            }
        });
    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG.MSG_UPDATE_PAY_PASSWORD_SUCCESS:
                        showToast("修改成功");
                        finish();
                        break;
                    case MSG.MSG_UPDATE_PAY_PASSWORD_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
